/**
 * Created by admin on 2016/6/25.
 */
var express = require('express'),
    http = require('http'),
    path = require('path');
var wx = require('./wx_jsapi')({redis:{RDS_PORT:6379,RDS_HOST :'61.147.98.134',RDS_AUTH:{}},wx:{app_id:'wxef9f343d05b97ba0', app_secret:'e26a35f3bf82b55de3dc01ffec680909'}});
var config = require('./config');
/*var wxconfig={
    app_id: config.wx.app_id,
    app_secret: config.wx.app_secret
};*/

var app = express();
app.set('port',1342);
app.get('/', function(req, res) {
    res.json('this is index');
});
app.get('/test', function(req, res) {
    var name = wx.test();
    wx.redis_test();
    res.json('this is '+name);
});
app.get('/getSignature', function(req, res) {
    var url = "http://mdev.guoran100.com";
    console.log(url);
    wx.getSignature()(url, function(error, result) {
        if (error) {
            res.json({
                'error': error
            });
        } else {
            res.json(result);
        }
    });
});
app.get('/getToken', function(req, res) {
    var url = "http://mdev.guoran100.com";
    console.log(url);
    wx.getToken()(function(error, result) {
        if (error) {
            res.json({
                'error': error
            });
        } else {
            res.json(result);
        }
    });
});
app.get('/getUserInfo', function(req, res) {
    wx.getUserInfo('oA7dTszNX7jPucCFmXPlea7C7A1s').then(function(error, result) {
        if (error) {
            res.json({
                'error': error
            });
        } else {

            res.json(result);
        }
    });
});

/*
var signature = require('../index');
var config = require('./config')();


app.get('/test', function(req, res) {
    var u = req.protocol + "://" + req.get('Host') + req.url;
    signature.getSignature(config)(u, function(error, result) {
        console.log(result);
        res.render(__dirname + '/public/test.html', result);
    });
});

app.post('/getsignature', function(req, res){
    var url = req.body.url;
    console.log(url);
    signature.getSignature(config)(url, function(error, result) {
        if (error) {
            res.json({
                'error': error
            });
        } else {
            res.json(result);
        }
    });
});

*/

http.createServer(app).listen(app.get('port'), function() {
    console.log("Express server listening on port " + app.get('port'));
});
